package com.w.proxy.player.testplayer;

import com.w.proxy.player.api.IPlayer;
import com.w.proxy.player.impl.LoLPlayer;
import com.w.proxy.player.playerproxy.cglib.LoLCglibDynamicProxy;
import com.w.proxy.player.playerproxy.jdk.LoLDynamicProxy;
import com.w.proxy.player.util.DateUtils;

/**
 * @author wyw
 * @description 测试方法
 */
public class TestPlayer {

    public static void main(String[] args) throws Throwable {
        IPlayer player = new LoLPlayer("wangyiwen");
        System.out.println("↓----------普通调用------------↓");
        player.login("2018-10-17 16:41:49");
        player.killMonster();
        player.levelUp();
        player.logout("2018-10-17 16:42:20");
        System.out.println("↑----------普通调用------------↑");

        System.out.println();
        System.out.println();

        System.out.println("↓----------JDK动态代理调用------------↓");
//        // 定义一个handler
//        InvocationHandler handler = new LoLDynamicProxy(player);
//        // 获得类的class loader
//        ClassLoader classLoader = player.getClass().getClassLoader();

        // 动态产生一个代理者
        IPlayer proxy = new LoLDynamicProxy(player).getProxy();
        proxy.login("2018-10-21 22:48:41");
        proxy.killMonster();
        proxy.levelUp();
        proxy.logout("2018-10-21 22:49:17");
        proxy.testInt(1);
        System.out.println("↑----------JDK动态代理调用------------↑");


        System.out.println("↓----------CGLIB动态代理调用------------↓");

        // 动态产生一个代理者
        //IPlayer cglibPorxy = LoLCglibDynamicProxy.CglibEnum.INSTANCE.getInstanceByEnum().getProxy(LoLPlayer.class);
        IPlayer cglibPorxy = LoLCglibDynamicProxy.getInstance().getProxy(LoLPlayer.class);
        cglibPorxy.login(DateUtils.toFullDateString(DateUtils.getNow()));
        cglibPorxy.killMonster();
        cglibPorxy.levelUp();
        cglibPorxy.logout(DateUtils.toFullDateString(DateUtils.getNow()));
        System.out.println("↑----------CGLIB动态代理调用------------↑");


    }
}
